package com.kylin.domain.user.provider;

import com.kylin.domain.user.command.CreateUserAddressCommand;
import com.kylin.domain.user.command.FindDefaultAddressCommand;
import com.kylin.domain.user.command.RemoveUserAddressCommand;
import com.kylin.domain.user.vo.UserAddressVO;
import com.kylin.shared.common.FunctionProvider;
import com.kylin.shared.common.consts.Constants;
import lombok.extern.slf4j.Slf4j;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.eventhandling.gateway.EventGateway;
import org.axonframework.queryhandling.QueryGateway;
import org.springframework.stereotype.Component;

/**
 * 用户地址功能服务
 * @author Damon S.
 * @version v1.0.1
 * @date 2021年01月01日 15:27
 */
@Slf4j
@Component
public final class UserAddressProvider extends FunctionProvider {

    public UserAddressProvider(QueryGateway queryGateway,
                               CommandGateway commandGateway,
                               EventGateway eventGateway) {
        super(queryGateway, commandGateway, eventGateway);
    }

    public boolean createUserAddress(CreateUserAddressCommand command) {
        Long addressId = sendCommand(command);
        return Constants.LONG_ONE < addressId;
    }

    public UserAddressVO findAddressDefault(FindDefaultAddressCommand command) {
        return executeQuery(
                command, UserAddressVO.class
        );
    }

    public boolean removeUserAddressById(RemoveUserAddressCommand command) {
        return sendCommand(command);
    }
}
